local ServerOHOH = _G.ServerOHOH;
local M = ServerOHOH.class.new(script, ServerOHOH.files.Server_PlayerComponent(),script.Parent.Name);
local function_list = ServerOHOH.function_list;
local GroupReward_cfg = ServerOHOH.config.GroupReward
local ItemTool=_G.CommonOHOH.load.ItemTool();

function M.new(self,...)
	return M(self,...);
end;

function M.ctor(self, parent)
	M.super.ctor(self, parent);
	self.DataBase=self.parent:GetComponent(ServerOHOH.load.Server_PlayerDataComponent())
    self.ItemCtrl=self.parent:GetComponent(ServerOHOH.load.Server_ItemCtrl())

end;

function M.GroupReward(self)
	if  not self.parent.main_inst:IsInGroup(GroupReward_cfg.groupId) then
		return false
	end
	local grdata=self.DataBase:GetData("groupReward")
	local rid=grdata.id
	local time=grdata.time
	-- print("GroupReward--->Enter:",rid,time,time-os.time())

	local cfg=GroupReward_cfg.reward[rid]
	if not cfg then
		return false
	end
	if time-os.time()>0 then
		return false
	end
	local newId=rid
	if newId+1<#GroupReward_cfg.reward then
		newId=newId+1
	else
		newId=1
	end
	self.DataBase:GetData("groupReward").id=newId
	self.DataBase:GetData("groupReward").time=os.time()+cfg.time


	local key,count= ItemTool.GetRewardByLevel(cfg.item_id,cfg.count,self.DataBase:GetData("base").level)

	local rd={[key]=count}
	-- print("======GroupReward===A==>",key,count)
	self.ItemCtrl:AddAnyThing(key,count,true,true,"groupReward")

	return rd
end
 
M:RegistFunction(function_list.group_reward,M.GroupReward)


return M
